<template>
  <view class="order_detail">
    <!-- #ifndef MP-WEIXIN -->
    <my-navbar
      leftText="订单详情"
      @leftClick="leftClick"
      leftIconColor="white"
      leftColor="white"
      url="https://copartner.oss-cn-beijing.aliyuncs.com/logo/2401/11/wgP26bV6qnoXRjGoHoVXvdy0W9OsiRMhJsb2ftw1.png"
    ></my-navbar>
    <!-- #endif -->
    <!-- 订单信息 -->
    <view class="content">
      <view class="content-top">
        <view class="content-top-icon">
          <image
            mode="aspectFill"
            src="https://copartner.oss-cn-beijing.aliyuncs.com/logo/2401/12/XPhgCmJPgPhTInV8ll97zKQuXbUzskPskDEaBLiu.png"
          ></image>
        </view>
        <view class="content-top-span">
          <text v-if="orderInfo.order_status == 0">待审核</text>
          <text v-else-if="orderInfo.order_status == 1">备货中</text>
          <text v-else-if="orderInfo.order_status == 2">配送中</text>
          <text v-else-if="orderInfo.order_status == 3">已完成</text>
          <text v-else-if="orderInfo.order_status == 4">已取消</text>
        </view>
      </view>
      <view class="content-bottom">
        <text v-if="orderInfo.order_status == 0"
          >货到付款，等待审核通过...</text
        >
        <text v-if="orderInfo.order_status == 1">已审核，等待备货发货</text>
        <text v-if="orderInfo.order_status == 2">备货完成，正在配送中...</text>
        <text v-if="orderInfo.order_status == 3"
          >您的订单已完成，欢迎您再次光临！</text
        >
        <text v-if="orderInfo.order_status == 4">您的订单已经成功取消</text>
      </view>
      <!-- 位置信息 -->
      <view class="address">
        <view class="address-time">{{ orderInfo.createdTime }}</view>
        <view class="address-content">
          <view class="address-content-left">
            <view class="leftIcon"></view>
            <view class="address-content-left-context">
              <text class="hidden addressName">{{ orderInfo.address }}</text>
              <text class="hidden addressLag"
                >{{ orderInfo.nickname }} {{ orderInfo.mobile }}</text
              >
            </view>
          </view>
        </view>
      </view>
    </view>
    <!-- 商品信息 -->
    <view class="goods">
      <my-orderDetailList
        v-for="(item, index) in goodsList"
        :key="index"
        :item="item"
        :orderInfo="orderInfo"
      ></my-orderDetailList>
      <view class="retract" v-if="allList.length>2">
        <view v-show="retract" @click="retract=!retract">
          <text>点击收起</text>
          <image
            src="https://copartner.oss-cn-beijing.aliyuncs.com/logo/2401/12/2FfqPySawNxcxxToNapLGgWvlHTP5vXRGvTplEaL.svg"
          ></image
        ></view>
        <view v-show="!retract" @click="retract=!retract">
          <text>剩余商品</text>
          <image
            src="https://copartner.oss-cn-beijing.aliyuncs.com/logo/2401/12/Z6cabUabn5CPG2TiMqMqSh3yJjRIt5nHFWpjGgCt.svg"
          ></image
        ></view>
      </view>
      <view class="goods-total">
        <view class="all">共{{ allList.length }}件</view>
        <view class="allPrice"
          >商品总金额：
          <text class="price"><text>￥</text>{{ orderInfo.order_money }}</text>
        </view>
      </view>
    </view>

    <view class="padding order_info">
      <view class="money">
        <view
          ><text>满减</text
          ><text class="gray_font"
            >￥{{ orderInfo.full_reduction_money }}</text
          ></view
        >
        <view
          ><text>优惠券</text
          ><text class="gray_font">￥{{ orderInfo.discount_money }}</text></view
        >
        <view
          ><text>运费</text
          ><text class="gray_font">￥{{ orderInfo.delivery_fee }}</text></view
        >
        <view
          ><text>下单金额</text
          ><text class="gray_font">￥{{ orderInfo.should_money }}</text></view
        >
        <view
          ><text>差额</text
          ><text class="gray_font">￥{{ orderInfo.balance }}</text></view
        >
        <view
          ><text>实付金额</text
          ><text class="red_font">￥{{ orderInfo.real_money }}</text></view
        >
        <view
          ><text>支付方式</text
          ><text class="gray_font">{{
            orderInfo.is_prior_payment == 1 ? "在线付款" : "货到付款"
          }}</text>
        </view>
        <view
          ><text>积分</text
          ><text class="gray_font">- {{ orderInfo.points }}</text></view
        >
        <view class="flex-btw bordertop">
          <text>支付信息</text>
          <text>{{ orderInfo.pay_status == 0 ? "未支付" : "已支付" }}</text>
        </view>
      </view>
      <view class="pay">
        <view
          ><text>下单时间</text><text>{{ orderInfo.createdTime }}</text></view
        >
        <view
          ><text>订单编号</text><text>{{ orderInfo.order_sn }}</text></view
        >
        <view
          ><text>配送日期</text><text>{{ orderInfo.send_time }}</text></view
        >
        <view v-if="orderInfo.send_time_id == 0"
          ><text>配送时间</text><text>不限</text></view
        >
        <view v-else
          ><text>配送时间</text><text>{{ startTime }}~{{ endTime }}</text></view
        >
        <view
          ><text class="prop">配送金额</text
          ><text
            >￥{{
              orderInfo.order_status == 2 || orderInfo.order_status == 3
                ? orderInfo.send_money
                : "0.00"
            }}</text
          >
        </view>
        <view
          ><text class="prop">退货金额</text
          ><text>￥{{ orderInfo.return_money }}</text></view
        >
        <view
          ><text class="prop">备注</text
          ><text>{{ orderInfo.remark }}</text></view
        >
      </view>

      <view v-if="settlement_info.length >= 1" class="money">
        <view class="flex-btw">
          <text class="title">结算记录</text>
        </view>
        <view v-for="settlement of settlement_info" :key="settlement.id">
          <text @click="toDetail(settlement.id)" class="line">{{
            settlement.order_sn
          }}</text>
          <text>￥{{ settlement.account_money }}</text>
        </view>
      </view>
      <view v-if="return_info.length >= 1" class="money">
        <view class="flex-btw">
          <text class="title">退货记录</text>
        </view>
        <view v-for="returns of return_info" :key="returns.id">
          <text @click="returninfo(returns.id)" class="line">{{
            returns.order_sn
          }}</text>
          <text>￥{{ returns.real_money }}</text>
        </view>
      </view>
      <view style="height: 20rpx"></view>
    </view>
  </view>
</template>

<script>
let app = getApp();
import { $https } from "@/static/js/request.js";
import MixinShowprice from "@/static/js/mixinshowprice.js";
export default {
  data() {
    return {
      logo: "",
      showLogo: 0,
      orderInfo: {}, //订单信息
      goodsList: [], //商品列表
      allList:[],
      startTime: "",
      endTime: "",
      return_info: [],
      settlement_info: [],
      type: 0,
      retract:false, // 收起
    };
  },
  mixins: [MixinShowprice],
  onReady() {
    getApp().setTitle();
  },
  onLoad(option) {
    this.getData(option.id);
    this.logo = uni.getStorageSync("logo");
    this.showLogo = uni.getStorageSync("showLogo");
  },
  onUnload() {
    // #ifdef MP-WEIXIN
    uni.$emit("updateorder", () => {});
    // #endif
  },
  watch:{
    retract(val){
      if(!val){
        this.goodsList = this.allList.slice(0,2)
      }else{
        this.goodsList = this.allList
      }
    }
  },
  methods: {
    getData(id) {
      $https(
        "GET",
        "getOrderDetail",
        {
          oid: id,
        },
        (res) => {
          this.type = res.data.data.order_info.is_prior_payment;
          this.return_info = res.data.data.return_info;
          this.settlement_info = res.data.data.settlement_info;
          var info = res.data.data.order_info;
          var ms = Number(info.created_at + "000");
          var now = new Date();
          now.setTime(ms);
          var date =
            now.getFullYear() +
            "-" +
            (now.getMonth() + 1) +
            "-" +
            now.getDate() +
            " " +
            now.getHours() +
            ":" +
            now.getMinutes() +
            ":" +
            now.getSeconds();
          info.createdTime = date;
          this.orderInfo = info;
          this.startTime = info.send_time_period.start_time;
          this.endTime = info.send_time_period.end_time;
          this.allList = res.data.data.goods_info;
          this.goodsList = res.data.data.goods_info.slice(0,2);
        }
      );
    },
    leftClick() {
      // #ifdef H5
      window.history.back(-1);
      // #endif
      // #ifndef H5
      uni.navigateBack();
      // #endif
    },
    toDetail(id) {
      let type = this.type == 0 ? 2 : 1;
      uni.navigateTo({
        url: `/subpack/user/final_statement/final_statement_detail?id=${id}&type=${type}`,
      });
    },
    returninfo(id) {
      uni.navigateTo({
        url: `/subpack/user/return_goods/return_goods_detail?id=${id}`,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  width: 750rpx;
  height: 400rpx;
  background-image: url("https://copartner.oss-cn-beijing.aliyuncs.com/logo/2401/10/QfgJI7gfEL8uIpGGtGNu0M1sU9c3FrFNethEEtUj.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  &-top {
    display: flex;
    align-items: center;
    color: white;
    margin-top: 30rpx;
    &-icon {
      width: 32rpx;
      height: 32rpx;
      margin-right: 20rpx;
      image {
        width: 100%;
        height: 100%;
      }
    }
    &-span {
      text {
        color: white;
        font-size: 36rpx;
      }
    }
  }
  &-bottom {
    margin-top: 30rpx;
    font-size: 24rpx;
    text {
      color: white;
    }
  }
}

.address {
  width: 690rpx;
  height: 200rpx;
  background: #fff;
  margin: 0 auto;
  border-radius: 20rpx;
  position: absolute;
  transform: translateY(210rpx);
  &-time {
    line-height: 22rpx;
    font-size: 22rpx;
    font-weight: 500;
    color: #999393;
    padding: 10rpx 0 10rpx;
    margin: 0 24rpx 0;
    border-bottom: 1rpx solid #ececec;
  }
  &-content {
    display: flex;
    width: calc(100% - 48rpx);
    height: 150rpx;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 0 24rpx 0 24rpx;
    &-left {
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      align-items: center;
      height: 100%;
      .leftIcon {
        width: 32rpx;
        height: 36rpx;
        background-image: url("https://copartner.oss-cn-beijing.aliyuncs.com/logo/2401/12/4oeTIaD2Qpkl0IT3WQEtNcTq0VJ6ihKPUAXFIM3e.png");
        background-size: 100% 100%;
      }
      &-context {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        height: 70%;
        margin-left: 30rpx;
        .hidden {
          width: 480rpx;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .addressName {
          font-size: 30rpx;
          font-weight: bold;
          color: #333333;
        }
        .addressLag {
          font-size: 24rpx;
          font-weight: 500;
          color: #999999;
        }
      }
    }
  }
}

.goods {
  width: calc(100% - 60rpx);
  margin: 40rpx auto;
  background: white;
  border-radius: 20rpx;
  .retract {
    view {
      display: flex;
      align-items: center;
      justify-content: center;
      text{
        font-size: 22rpx;
        color: #999999;
      }
      image {
        width: 18rpx;
        height: 10rpx;
        margin-left: 10rpx;
      }
    }
  }
  &-total {
    text-align: right;
    padding: 0 20rpx 20rpx;
    box-sizing: border-box;
    .all {
      font-size: 22rpx;
      color: #999999;
      margin-bottom: 10rpx;
    }
    .allPrice {
      font-size: 22rpx;
      color: #333333;
      .price {
        font-size: 30rpx;
        color: #f55726;
        text {
          font-size: 18rpx;
          color: #f55726;
        }
      }
    }
  }
}

.order_info {
  .bordertop {
    border-top: 1rpx solid #ececec;
    padding: 20rpx 0;
  }
  .prop {
    white-space: nowrap;
    margin-right: 20rpx;
  }

  .pay > view,
  .money > view {
    margin-top: 20rpx;
  }

  .gray_font {
    color: gray;
  }
}

.order_detail {
  .pay > view,
  .money > view {
    display: flex;
    justify-content: space-between;
  }

  .pay,
  .money {
    width: 690rpx;
    background: white;
    border-radius: 10rpx;
    padding: 10rpx 30rpx;
    margin-bottom: 20rpx;
  }

  .pay > view:nth-child(n + 2) text:last-child {
    color: gray;
  }

  .good_info {
    padding-top: 25rpx;
  }

  .title {
    font-size: 28rpx;
    font-weight: bold;
  }
}

.good_info {
  padding-bottom: 40rpx;

  .title {
    margin-bottom: 14rpx;
  }

  .sign_good {
    font-size: 24rpx;
    background: #fff;
    border-radius: 14rpx;
    padding: 20rpx;
    margin-top: 20rpx;

    + .sign_good {
      margin-top: 20rpx;
    }

    .yellow_tag {
      font-size: 20rpx;
      padding: 2rpx 12rpx;
      background: #ff9900;
      border-radius: 6rpx;
      color: #fff;
      margin-left: 8rpx;
    }

    .top {
      margin-bottom: 20rpx;

      .imgs {
        width: 120rpx;
        height: 120rpx;
        position: relative;

        .logo {
          width: 40rpx;
          height: 40rpx;
          position: absolute;
          top: 0;
          left: 0;
          z-index: 1;
        }

        .img {
          width: 120rpx;
          max-height: 100rpx;
          margin-right: 40rpx;
        }
      }

      .name {
        margin-left: 20rpx;
      }
    }

    .row {
      margin-bottom: 20rpx;

      text:first-child {
        display: inline-block;
        width: 60%;
      }
    }

    .note {
      color: #9a9a9a;
      white-space: normal;
      word-break: break-all;
    }

    .spu {
      margin-left: 20rpx;
      padding: 4rpx 8rpx;
      background: #f5f5f5;
      border-radius: 8rpx;
      font-size: 24rpx;
      transform: scale(0.8);
    }
  }
}

.line {
  color: #0f0acb;
  text-decoration: underline;
}

text {
  font-size: 26rpx;
  color: #333;
}
</style>
